package com.hc.lifecycle;

import com.hc.service.BbService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/6/9 15:02
 */
@Service
@Slf4j
public class InitService implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean {

    private String name;

    @Autowired
    private BbService bbService;

    public InitService() {
        log.info("1、Bean构造");
    }

    @Value("张三")
    public void setName(String name) {
        log.info("2、setName：{}", name);
        this.name = name;
    }

    public void setBbService(BbService bbService) {
        log.info("2、依赖注入属性：bbService");
        this.bbService = bbService;
    }

    @Override
    public void setBeanName(String s) {
        log.info("3、set bean名称：{}", s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        log.info("3、set bean工厂");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info("3、set 上下文");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("5、bean InitializingBean");
    }

    @PostConstruct
    public void init() {
        log.info("5、自定义init方法");
    }

    @Override
    public void destroy() throws Exception {
        log.info("7、bean销毁");
    }

}
